﻿using System.Runtime.InteropServices;

namespace CacheSharp.Core
{
    /// <summary>
    /// WinAPI平台调用
    /// </summary>
    internal class WinApiHelper
    {
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool GlobalMemoryStatusEx([In, Out] MEMORYSTATUSEX lpBuffer);

        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        // ReSharper disable once InconsistentNaming
        public class MEMORYSTATUSEX
        {
            public uint dwLength;

            public uint dwMemoryLoad;

            public ulong ullAvailExtendedVirtual;

            public ulong ullAvailPageFile;

            public ulong ullAvailPhys;

            public ulong ullAvailVirtual;

            public ulong ullTotalPageFile;

            public ulong ullTotalPhys;

            public ulong ullTotalVirtual;

            public MEMORYSTATUSEX()
            {
                dwLength = (uint) Marshal.SizeOf(typeof (MEMORYSTATUSEX));
            }
        }
    }
}